package controllers

import (
	"github.com/gin-gonic/gin"
	"gowww/comeon/services"
	"net/http"
)

//
//  Add
//  @Description: 添加用户
//  @param c
//
func Add(c *gin.Context) {
	var adminService services.Admin
	if err := c.ShouldBindJSON(&adminService); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	id, err := adminService.Add()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    10001,
			"message": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    0,
		"message": "success",
		"data":    id,
	})
}

//
//  Login
//  @Description: 登录
//  @param c
//
func Login(c *gin.Context) {
	var adminService services.Admin
	if err := c.ShouldBindJSON(&adminService); err != nil {
		c.JSON(http.StatusOK, gin.H{"code": 10001, "message": err.Error()})
		return
	}
	retData, err := adminService.Login()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    10001,
			"message": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    "0",
		"message": "success",
		"data":    retData,
	})
}
